package com.ruoyi.fault.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fault.domain.FaultReport;
import com.ruoyi.fault.service.IFaultReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 故障报修Controller
 * 
 * @author silence
 * @date 2025-07-21
 */
@RestController
@RequestMapping("/fault/report")
public class FaultReportController extends BaseController
{
    @Autowired
    private IFaultReportService faultReportService;

    /**
     * 查询故障报修列表
     */
    @PreAuthorize("@ss.hasPermi('fault:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(FaultReport faultReport)
    {
        startPage();
        List<FaultReport> list = faultReportService.selectFaultReportList(faultReport);
        return getDataTable(list);
    }

    /**
     * 导出故障报修列表
     */
    @PreAuthorize("@ss.hasPermi('fault:report:export')")
    @Log(title = "故障报修", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FaultReport faultReport)
    {
        List<FaultReport> list = faultReportService.selectFaultReportList(faultReport);
        ExcelUtil<FaultReport> util = new ExcelUtil<FaultReport>(FaultReport.class);
        util.exportExcel(response, list, "故障报修数据");
    }

    /**
     * 获取故障报修详细信息
     */
    @PreAuthorize("@ss.hasPermi('fault:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(faultReportService.selectFaultReportById(id));
    }

    /**
     * 新增故障报修
     */
    @PreAuthorize("@ss.hasPermi('fault:report:add')")
    @Log(title = "故障报修", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaultReport faultReport)
    {
        return toAjax(faultReportService.insertFaultReport(faultReport));
    }

    /**
     * 修改故障报修
     */
    @PreAuthorize("@ss.hasPermi('fault:report:edit')")
    @Log(title = "故障报修", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaultReport faultReport)
    {
        return toAjax(faultReportService.updateFaultReport(faultReport));
    }

    /**
     * 删除故障报修
     */
    @PreAuthorize("@ss.hasPermi('fault:report:remove')")
    @Log(title = "故障报修", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(faultReportService.deleteFaultReportByIds(ids));
    }
}
